package com.bravo.mvpkotlin.ui.detail

import android.support.v7.widget.LinearLayoutManager
import com.bravo.mvpkotlin.R
import com.bravo.mvpkotlin.base.AppComponent
import com.bravo.mvpkotlin.base.BaseActivity
import com.bravo.mvpkotlin.data.Repo
import com.bravo.mvpkotlin.data.User
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.activity_detail.*
import javax.inject.Inject

class DetailActivity : BaseActivity(),DetailViews {


    override fun attachLayoutId():Int = R.layout.activity_detail

    @Inject
    lateinit var adapter:DetailAdapter

    @Inject
    lateinit var presenter:DetailPersenter

    override fun initViews() {
        var user = intent.getParcelableExtra<User>("user")
        Glide.with(this).load(user.avatar_url).into(detail_avatar)
        detail_name.text = user.name
        detailRecyclerView.layoutManager = LinearLayoutManager(this)
        detailRecyclerView.adapter = adapter
        presenter.getRepos(user.repos_url)
    }

    override fun setUpComponent(appComponent: AppComponent) {
        DaggerDietailActivityComponent.builder().appComponent(appComponent).detailActivityModuel(DetailActivityModuel(this)).build().inject(this)
    }

    override fun showRepo(it: List<Repo>?) {
        stopLoading()
        adapter.updateDatas(it!!)
    }

}
